﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using CapaEntidades;
using CapaDatos;

namespace CapaNegocio
{
    public class negReserva
    {
        #region singleton
        private static readonly negReserva _instancia = new negReserva();
        public static negReserva Instancia
        {
            get { return negReserva._instancia; }
        }
        #endregion

        #region Metodos
        public int RegistrarReserva(DataTable dtReserva, entCliente c, entPago p, char estado)
        {
            DataRow Cr = dtReserva.Rows[0];
            try
            {
                String cadXML = "<root>";
                cadXML += "<reserva ";
                cadXML += "IdPersona= '" + c.IdPersona + "' ";
                cadXML += "FechaEntrada= '" + Cr["FechaIngreso"] + "' ";
                cadXML += "FechaSalida= '" + Cr["FechaSalida"] + "' ";
                cadXML += "NroNoches= '" + Cr["NroNoches"] + "' ";
                cadXML += "MontoPagado= '" + p.Pagado + "' ";
                cadXML += "Saldo= '" + (p.Total - p.Pagado) + "' ";
                cadXML += "EstadoReserva= '" + estado + "' >";
                foreach (DataRow r in dtReserva.Rows)
                {
                    cadXML += "<detreserva ";
                    cadXML += "IdHabitacion= '" + r["IdHabitacion"] + "' ";
                    cadXML += "PrecioHabitacion= '" + r["Precio"] + "' />";
                }
                cadXML += "</reserva></root>";
                int i = datReserva.Instancia.RegistrarReserva(cadXML);
                return i;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public List<entReserva> ListarHistorialReservas(int idCliente)
        {
            return datReserva.Instancia.ListarHistorialReservas(idCliente);
        }
        public DataTable BuscarReservaPorID(int idReserva)
        {
            return datReserva.Instancia.BuscarReservaPorID(idReserva);
        }
        #endregion
    }
}
